﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using NFine.Util;
using NFine.Data.Dto.SystemManage;
using NFine.Data.Entity.SystemManage;
using NFine.Service.SystemManage;
using NFine.Web.Controllers;
using SharpRepository.Repository;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using NFine.Web.Attributes;

namespace NFine.Web.Areas.SystemManage.Controllers
{
    [Area("SystemManage")]
    public class TenantController : NFineController
    {
        private readonly TenantService _tenantService;
        public TenantController(TenantService tenantService)
        {
            _tenantService = tenantService;
        }
        public IActionResult Index()
        {
            return View();
        }
        public IActionResult List()
        {
            return View();
        }
        public IActionResult Form()
        {
            return View();
        }
        public IActionResult Details()
        {
            return View();
        }

        [HttpGet]
        public JsonResult GetGridJson(Pagination pagination, string keyword)
        {
            var data = new
            {
                rows = _tenantService.GetList(pagination, keyword),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Json(data);
        }

        [HttpGet]
        public JsonResult GetFormJson(string keyValue)
        {
            var data = _tenantService.GetForm(keyValue);
            return Json(data);
        }

        [HttpPost]
        public JsonResult SubmitForm(TenantInputDto tenantInputDto, string keyValue)
        {
            _tenantService.SubmitForm(tenantInputDto, keyValue);
            return Success("操作成功。");
        }

        [HttpPost]
        public JsonResult DeleteForm(string keyValue)
        {
            _tenantService.DeleteForm(keyValue);
            return Success("操作成功。");
        }
        [HttpPost]
        public JsonResult EnabledForm(string keyValue)
        {
            _tenantService.EnabledForm(keyValue);
            return Success("账户启用成功。");
        }
        [HttpPost]
        public JsonResult DisabledForm(string keyValue)
        {
            _tenantService.DisabledForm(keyValue);
            return Success("账户禁用成功。");
        }
    }
}